<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        div {
            width: 100%;
            height: 100%;
        }

        #list1 {
            position: fixed;
            top: 100px;
            left: 50px;
        }

        ul,
        li {
            list-style: none;


        }

        #list1 li {
            width: 50px;
            height: 30px;
            font-size: 20px;
            line-height: 30px;
            text-align: center;
            margin-bottom: 20px;
            border: 1px solid #000;
            background: red;
            cursor: pointer;
        }

        #list2 {
            width: 100%;

        }

        #list2 li {
            width: 100%;
            border: 1px solid #ccc;

        }

        #list2 li:nth-child(1) {
            background: gold;

        }

        #list2 li:nth-child(2) {
            background: green;

        }

        #list2 li:nth-child(3) {
            background: pink;

        }

        #list2 li:nth-child(4) {
            background: greenyellow;

        }

        #list1 .active {
            background-color: green;

        }
    </style>
</head>

<body>
    <div>
        <ul id="list1">
            <li>F1</li>
            <li>F2</li>
            <li>F3</li>
            <li>F4</li>
        </ul>
        <ul id="list2">
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </div>
</body>
<script>
    (function () {
        // var list2 = document.querySelector('#list2');
        var a_list1 = document.querySelectorAll('#list1 li'); //按钮集合

        var a_list2 = document.querySelectorAll('#list2 li'); //楼层集合

        for (let i = 0; i < a_list2.length; i++) {

            a_list2[i].style.height = window.innerHeight + 'px';

        }
        var one_screenY = window.innerHeight;
        for (let i = 0; i < a_list1.length; i++) {

            a_list1[i].index = i;

            a_list1[i].onclick = function () {
                console.log(a_list1[i]);
                for (let j = 0; j < a_list1.length; j++) {

                    a_list1[j].className = '';

                }

                this.className = 'active';

                window.scrollTo(0, one_screenY * this.index);
            }
        }
        window.onscroll = function () {
            var scoy = window.scrollY;
            for (let i = 0; i < a_list2.length; i++) {
                if (scoy >= a_list2[i].offsetTop) {
                    for (let j = 0; j < a_list1.length; j++) {
                        a_list1[j].className = '';
                    }
                    a_list1[i].className = 'active';
                }
            }
        }

    })();
</script>

</html>